﻿
/*

The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at 
  
http://www.mozilla.org/MPL/ 
  
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License. 
  
The Original Code is AST'r Framework.
  
The Initial Developer of the Original Code is
ALCARAZ Marc (aka eKameleon) <ekameleon@gmail.com>.
Portions created by the Initial Developer are Copyright (C) 2004-2011
the Initial Developer. All Rights Reserved.
  
Contributor(s) :
  
 */
package egallery.basic.process 
{
    import egallery.basic.logging.logger;
    import egallery.basic.models.PictureModel;
    import egallery.basic.vo.PictureVO;
    
    import system.process.Runnable;
    
    /**
     * Initialize the application.
     */
    public class InitApplication implements Runnable 
    {
        /**
         * Creates a new InitApplication instance.
         */
        public function InitApplication()
        {
            super() ;
        }
        
        /**
         * The default Array representation of all PictureVO to fill in the gallery when the application is initialized.
         */
        public var datas:Array ;
        
        /**
         * The IoC factory reference.
         */
        public var model:PictureModel ;
        
        /**
         * Run the process
         */
        public function run( ...arguments:Array ):void 
        {
            logger.debug(this + " init.") ;
            if ( model == null )
            {
                logger.warn(this + " fill the model failed with an empty model in the ECMAObjectFactory of the application.") ;
            }
            else
            {
                if ( datas == null && datas.length == 0 )
                {
                    logger.warn(this + " fill the model failed with an empty external datas Array.") ;
                    return ;
                }
                var size:int = datas.length ;
                for ( var i:int ; i < size; i++ )
                {
                    model.addVO( datas[i] as PictureVO ) ;
                }
                if ( model.size() > 0 )
                {
                    model.run() ;
                }
                else
                {
                    logger.warn(this + " run the model failed with an empty picture model.") ;
                }
            }
        }
    }
}
